/**
 * 
 */
package cn.mibcxb.java.dolphin.common;

import java.util.regex.Pattern;

import org.apache.commons.lang3.StringUtils;

/**
 * @author CXB
 * 
 */
public class Commons {
	public static final int BUFFER_LENGTH = 8096;

	public static final int MSG_PORT = 44444;

	public static final String SEPARATOR = ">=-=<";

	public static Status verifyDolphinData(DolphinData data) {
		// 1. check NULL
		if (null == data) {
			return Status.NULL_DATA;
		}

		// 2. check address
		if (null != data.getFromAddr()
				&& StringUtils.isBlank(data.getFromAddr().toString())) {
			return Status.NO_ADDRESS;
		}
		if (null != data.getToAddr()
				&& StringUtils.isBlank(data.getToAddr().toString())) {
			return Status.NO_ADDRESS;
		}

		return Status.OK;
	}

	public static String getErrorMessage(Status status) {
		String msg = null;
		return msg;
	}

	public static boolean isIP(String str) {
		boolean result = false;
		Pattern pattern = Pattern
				.compile("\\b((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\."
						+ "((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\."
						+ "((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\."
						+ "((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\b");
		result = pattern.matcher(str).matches();
		return result;
	}
}
